package com.neko.Thread_Learning;

/**
 * 15、daemon 守护线程
 * --------------------
 *  1、测试守护线程 ： 上帝 daemon 你 user_thread
 *
 *
 * */
public class t15_Daemon {

    public static void main(String[] args) {

        God_daemon god_daemon = new God_daemon();
        You_user you_user = new You_user();

        Thread thread_god = new Thread(god_daemon);
        thread_god.setDaemon(true);
            // Daemon() Default：false == 用户线程
        thread_god.start();

        Thread thread_you = new Thread(you_user);
        thread_you.start();
    }

}


class You_user implements Runnable {
    @Override
    public void run() {
        for (int i=0; i<365; i++) {
            System.out.println("你一生都开心的活着..");
        }

        System.out.println("===== goodbye God ========");
            // 【用户线程】全部结束后，【虚拟机】就会慢慢停止。停止之前，daemon还要跑一会儿
    }
}

class God_daemon implements Runnable {
    @Override
    public void run() {
        while (true) {
            System.out.println("上帝保佑着你...");
        }
    }
}

